package c_leetcode.a_70_climbing_stairs;

/**
 * 动态规划
 * 时间复杂度    O(n)
 * 空间复杂度    O(n）
 *
 * @author He Kuntao
 * @since 2025/2/21 10:59
 */
public class Dynamic {

    public static void main(String[] args) {
        Dynamic dynamic = new Dynamic();
        System.out.println(dynamic.climbStairs(5));
    }

    public int climbStairs(int n) {
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        int[] dp = new int[n + 1];
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i < dp.length; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        return dp[n];
    }
}
